package com.itheima.health.controller;

import com.itheima.health.common.MessageConst;
import com.itheima.health.entity.Result;
import com.itheima.health.service.OrderService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Map;

@Slf4j
@RestController
@RequestMapping("/mobile/order")
public class MobileOrderController {
    @Autowired
    private OrderService orderservice;

    /**
     * 根据id返回预约的部分信息
     * @param id 预约的id
     * @return
     */
    @GetMapping("/findById")
    public Result findById(Integer id){
        log.info("[接收的id为]：{}",id);
        //map用来存储返回的数据
        Map map = orderservice.findById(id);
        log.info("[输出的预约数据]：{}",map);
        //调整返回的日期格式为中国习惯格式
        if(map != null){
            Date orderDate = (Date) map.get("orderDate");
            SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
            String date = simpleDateFormat.format(orderDate);
            map.put("orderDate",date);
        }
        return new Result(true, MessageConst.QUERY_ORDER_SUCCESS,map);
    }
}
